#ifndef SESSIONMANAGER_H
#define SESSIONMANAGER_H

#include <QObject>
#include <QStack>
#include <QFileInfo>
#include <QSettings>
#include "session.h"

//#include "imgmgr.h"

/*************************************************************************/

class SessionManager : public QSettings
{
    Q_OBJECT

private:
    QString m_currentFileName;
    const QString& currentFileName () const { return m_currentFileName; }
    QHash<QString, Session> m_sessions;
    QStack<Session*> m_undoStack;
    QStack<Session*> m_redoStack;


    //----------
    void addSession (const QString &fileName,
                     const int page,
                     const double scale,
                     const int contrast,
                     const qreal zoom1,
                     const qreal zoom2,
                     const int removeMargins,
                     const int rotation,
                     const QString &text,
                     const QList<QRect> &greenRects,
                     const QList<QRect> &redRects,
                     const QDateTime &dateTime);
    void addSession (const Session &session);


private slots:
    void setCurrentFileName (const QString name) { m_currentFileName = name; }

public:
    explicit SessionManager (const QString & fileName, Format format, QObject * parent = 0);
    ~SessionManager ();

    void removeSession (const QString& fileName) { m_sessions.remove (fileName); }
    Session* sessionOf (const QString& fileName);
    Session* currentSession () { return sessionOf (currentFileName ()); }
    QStringList recentFileList (const int max = 10) const;

    bool canUndo () const { return !m_undoStack.isEmpty (); }
    bool canRedo () const { return !m_redoStack.isEmpty (); }

    Session* prepareUndo ();
    Session* undoSession ();
    Session *redoSession ();
    Session *prepareRedo ();

public slots:
    void clearUndo ();
    void clearRedo ();
    void clear ();
    void save ();
    void restore ();

signals:
    void undoIsPossible (bool b);
    void redoIsPossible (bool b);

};

#endif // SESSIONMANAGER_H
